<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    
    <meta name="referrer" content="no-referrer-when-downgrade">
    
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <script>if (/*@cc_on!@*/false || (!!window.MSInputMethodContext && !!document.documentMode)) window.location.href="https://support.dmeng.net/upgrade-your-browser.html?referrer="+encodeURIComponent(window.location.href); </script>
    
    
        <link rel="preload" crossorigin="crossorigin" href="/fonts/roboto/Roboto-Regular.woff2" as="font">
        <link rel="preload" crossorigin="crossorigin" href="/fonts/roboto/Roboto-Bold.woff2" as="font">
    
    
    
        <link rel="shortcut icon" href="/icons/favicon.ico">
    

    
    
        
<link rel="stylesheet" href="/css/mdui.min.v1.0.0.css">

    
    
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/css/iconfont.css">


    
    

    
        <script data-ad-client="ca-" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    












          


    
    
    <title>
        
            Git 学习笔记 | 举个栗子
        
    </title>
    
    
<meta name="generator" content="Hexo 5.2.0"></head>
<body class="mdui-drawer-body-left mdui-appbar-with-toolbar mdui-theme-primary-teal mdui-theme-accent-blue">
  
  <header class="mdui-appbar mdui-appbar-fixed">
  <div id="toolbar" class="mdui-toolbar mdui-color-theme">
    <button class="mdui-btn mdui-btn-icon" mdui-drawer="{target: '#sidebar', swipe: true}"><i class="iconfont icon-menu"></i></button>
    <a href="/" class="mdui-typo-headline">举个栗子</a>
    <a href="/" class="header-subtitle mdui-typo-headline">举个栗子</a>
    <div class="mdui-toolbar-spacer"></div>
    <button class="mdui-btn mdui-btn-icon" mdui-dialog="{target: '#search'}" mdui-tooltip="{content: 'search'}"><i class="iconfont icon-search"></i></button>
  </div>
</header>

<div class="mdui-dialog" id="search">
  
    <div class="search-form">
      <input type="search" class="search-form-input" placeholder="请输入关键字" onfocus="listenSearchFunc()">
    </div>
    <div class="search-result" data-resource="/search.xml"></div>
  
</div>

  <aside id="sidebar" class="mdui-drawer">
    <div class="mdui-tab" mdui-tab>
        <a href="#sidebar-tab1" id="sidebartab" class="mdui-ripple mdui-tab-active">站点概览</a>
        <a href="#sidebar-tab2" id="sidebartab" class="mdui-ripple">关于</a>
    </div>

    
    <div id="sidebar-tab1" class="mdui-p-a-1">
        <div class="mdui-list">
            
                
                <a href="/" class="mdui-list-item mdui-ripple">
                    <div class="mdui-list-item-icon">
                        <i class="iconfont icon-home"></i>
                    </div>
                    <div class="mdui-list-item-content">主页</div>
                </a>
            
                
                <a href="/tags/" class="mdui-list-item mdui-ripple">
                    <div class="mdui-list-item-icon">
                        <i class="iconfont icon-bookmark"></i>
                    </div>
                    <div class="mdui-list-item-content">标签</div>
                </a>
            
                
                <a href="/categories/" class="mdui-list-item mdui-ripple">
                    <div class="mdui-list-item-icon">
                        <i class="iconfont icon-folder"></i>
                    </div>
                    <div class="mdui-list-item-content">分类</div>
                </a>
            
                
                <a href="/archives/" class="mdui-list-item mdui-ripple">
                    <div class="mdui-list-item-icon">
                        <i class="iconfont icon-archive"></i>
                    </div>
                    <div class="mdui-list-item-content">归档</div>
                </a>
            
                
                <a href="/tools/" class="mdui-list-item mdui-ripple">
                    <div class="mdui-list-item-icon">
                        <i class="iconfont icon-tools"></i>
                    </div>
                    <div class="mdui-list-item-content">工具箱</div>
                </a>
            
                
                <a href="/about/" class="mdui-list-item mdui-ripple">
                    <div class="mdui-list-item-icon">
                        <i class="iconfont icon-user"></i>
                    </div>
                    <div class="mdui-list-item-content">关于</div>
                </a>
            
            <div class="mdui-list-item mdui-ripple">
                <div class="mdui-list-item-icon">
                    <i class="iconfont icon-moon"></i>
                </div>
                <div class="mdui-list-item-content">夜间模式</div>
                <label class="mdui-switch" id="darkmode">
                  <input type="checkbox" id="nightmode_switch"/>
                  <i class="mdui-switch-icon"></i>
                </label>
            </div>           
        </div>
    </div>

    
    <div id="sidebar-tab2" class="mdui-p-a-1">
        <div class="sidebar-overview">
            <div class="sidebar-avatar">
                
                    <img src="/icons/avatar.gif"/>
                
            </div>
            <div class="sidebar-author-name">Demo deom</div>
            <div class="sidebar-description">举个栗子 个人博客</div>
        </div>
        <div class="sidebar-links">
            
                
                <div class="mdui-chip">
                    <span class="mdui-chip-icon"><i class="iconfont icon-mail"></i></span>
                    <a href="mailto:xxx@xxx.com" class="mdui-chip-title">E-Mail</a>
                </div>
            
                
                <div class="mdui-chip">
                    <span class="mdui-chip-icon"><i class="iconfont icon-github"></i></span>
                    <a target="_blank" rel="noopener" href="https://your.url" class="mdui-chip-title">GitHub</a>
                </div>
            
                
                <div class="mdui-chip">
                    <span class="mdui-chip-icon"><i class="iconfont icon-steam"></i></span>
                    <a target="_blank" rel="noopener" href="https://your.url" class="mdui-chip-title">Steam</a>
                </div>
            
                
                <div class="mdui-chip">
                    <span class="mdui-chip-icon"><i class="iconfont icon-weibo"></i></span>
                    <a target="_blank" rel="noopener" href="https://your.url" class="mdui-chip-title">Weibo</a>
                </div>
            
        </div>
        <ul class="mdui-list" mdui-collapse="{accordion: true}">
            <li class="mdui-collapse-item">
                <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
                    <div class="mdui-list-item-icon">
                        <i class="iconfont icon-link"></i>
                    </div>
                    <div class="mdui-list-item-content">友情链接</div>
                    <div class="mdui-collapse-item-arrow">
                        <i class="mdui-list-item-icon iconfont icon-angle-down"></i>
                    </div>
                </div>
                <ul id="linksList" class="mdui-collapse-item-body mdui-list mdui-list-dense">
                    
                        <a target="_blank" rel="noopener" href="https://garybear.cn/hexo-theme-meadow/" class="mdui-list-item mdui-ripple">
                            Meadow说明文档
                        </a>
                    
                </ul>
            </li>
        </ul>
    </div>

    <div class="mdui-divider"></div>
    
    
</aside>
  
  <main id="main-contain" class="mdui-container mdui-m-t-5">
    <article id="article" class="mdui-card mdui-p-b-2 mdui-m-b-5">
  <header class="mdui-card-media">
    
    
      <div class="post-header"> 
  <a class="post-header-title" href="/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">Git 学习笔记</a>
  <div class="post-header-meta">
    <span>
      <span class="iconfont icon-calendar"></span>
      发布于:&nbsp;2020-10-20
    </span>
    <span>
      <span class="iconfont icon-calendar-check"></span>
      更新于:&nbsp;2021-03-03
    </span>
    <span>
      <span class="iconfont icon-folder"></span>
      分类于:&nbsp;
    </span>
    
      <span>
        <span class="iconfont icon-eye"></span>
        阅读次数:&nbsp;
        <span id="busuanzi_container_page_pv"><span id="busuanzi_value_page_pv"></span></span>
      </span>
    
  </div>
</div>   
    



    
    
    <div class="mdui-card-menu">
    
      <button class="mdui-btn mdui-btn-icon mdui-text-color-teal" mdui-menu="{target: '#share_menu', align: 'right'}"><i class="iconfont icon-share"></i></button>
      <ul class="mdui-menu" id="share_menu">
        <li class="mdui-menu-item">
          <a href="http://service.weibo.com/share/share.php?appkey=&title=Git 学习笔记&url=http://example.com/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/&pic=http://example.com/null&searchPic=false&style=simple" target="_blank" class="mdui-ripple">分享到 Weibo</a>
        </li>
        <li class="mdui-menu-item">
          <a href="https://twitter.com/intent/tweet?text=Git 学习笔记&url=http://example.com/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/&via=Demo deom" target="_blank" class="mdui-ripple">分享到 Twitter</a>
        </li>
        <li class="mdui-menu-item">
          <a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" target="_blank" class="mdui-ripple">分享到 Facebook</a>
        </li>
        <li class="mdui-menu-item">
          <a href="https://plus.google.com/share?url=http://example.com/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" target="_blank" class="mdui-ripple">分享到 Google+</a>
        </li>
        <li class="mdui-menu-item">
          <a href="https://www.linkedin.com/shareArticle?mini=true&url=http://example.com/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/&title=Git 学习笔记" target="_blank" class="mdui-ripple">分享到 LinkedIn</a>
        </li>
        <li class="mdui-menu-item">
          <a href="http://connect.qq.com/widget/shareqq/index.html?site=举个栗子&title=Git 学习笔记&summary=举个栗子 个人博客&pics=http://example.com/null&url=http://example.com/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" target="_blank" class="mdui-ripple">分享到 QQ</a>
        </li>
        <li class="mdui-menu-item">
          <a href="https://telegram.me/share/url?url=http://example.com/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/&text=Git 学习笔记" target="_blank" class="mdui-ripple">分享到 Telegram</a>
        </li>
      </ul>
    
  </div>
  </header>
  
  
  
  
  <div class="post-tags">
    
      <i class="iconfont icon-tag">
        <a rel="tag" href = /tags/Git/ >Git</a>
      </i>
    
  </div>

  
  <div class="mdui-card-content mdui-typo mdui-p-x-4">
    <p>Git 学习笔记</p>
<a id="more"></a>

<h2 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h2><h3 id="用户信息配置"><a href="#用户信息配置" class="headerlink" title="用户信息配置"></a>用户信息配置</h3><p>–global 当前用户所有仓库有效<br>–local 只对某个仓库生效<br>–system 对当前系统的所有用户有效</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name <span class="string">&quot;user_name&quot;</span></span><br><span class="line">git config --global user.email <span class="string">&quot;example@email.com&quot;</span></span><br></pre></td></tr></table></figure>

<p>优先级: local -&gt; global -&gt; system</p>
<h3 id="查看配置"><a href="#查看配置" class="headerlink" title="查看配置"></a>查看配置</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git config --list --global</span><br><span class="line">git config --list --<span class="built_in">local</span></span><br><span class="line">git config --list --system</span><br></pre></td></tr></table></figure>

<h2 id="基本使用"><a href="#基本使用" class="headerlink" title="基本使用"></a>基本使用</h2><ol>
<li>克隆代码: <code>git clone project url</code></li>
<li>将代码从工作区添加到暂存区: <code>git add filename</code></li>
<li>提交代码到版本库: <code>git commit -m &quot;commit content&quot;</code></li>
<li>拉取最新代码: <code>git pull</code></li>
<li>推送代码到远端仓库: <code>git push</code></li>
</ol>
<p>注: 推送代码之前, 一定要先拉取最新代码</p>
<h3 id="Clone"><a href="#Clone" class="headerlink" title="Clone"></a>Clone</h3><p>克隆远程仓库到本地, 例如: </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://gitee.com/aifenxiang/aifenxiang.git</span><br></pre></td></tr></table></figure>

<p>默认克隆到当前目录, 可以手动指定目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://gitee.com/aifenxiang/aifenxiang.git  ~/Git/blog</span><br></pre></td></tr></table></figure>

<h3 id="Add"><a href="#Add" class="headerlink" title="Add"></a>Add</h3><p>将代码从工作区添加到缓存区</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git add </span><br></pre></td></tr></table></figure>

<h3 id="初始化仓库"><a href="#初始化仓库" class="headerlink" title="初始化仓库"></a>初始化仓库</h3><p>如果项目已经存在, 切换到项目目录然后执行 <code>git init</code><br>如果项目还没创建, 可以使用 <code>git init project_name</code></p>
<h3 id="查看仓库状态"><a href="#查看仓库状态" class="headerlink" title="查看仓库状态"></a>查看仓库状态</h3><p><code>git status</code> 查看当前仓库状态</p>
<h3 id="添加到缓存区"><a href="#添加到缓存区" class="headerlink" title="添加到缓存区"></a>添加到缓存区</h3><p>例如: <code>git add ./demo.html</code> 添加 <code>demo.html</code> 文件到缓存区;<br>如果修改的文件过多,可以使用 <code>git add .</code> 添加当前目录下的所有文件到缓存区<br>注意: <code>git add .</code> 会忽略空目录;  如果需要添加空目录, 需要使用 <code>git add empty_dir_name</code></p>
<h3 id="提交到版本库"><a href="#提交到版本库" class="headerlink" title="提交到版本库"></a>提交到版本库</h3><p>使用 <code>git commit -m &quot;提交说明&quot;</code> 将缓存区的修改提交到版本库</p>
<h3 id="查看提交日志"><a href="#查看提交日志" class="headerlink" title="查看提交日志"></a>查看提交日志</h3><p>使用 <code>git log</code> 查看提交日志</p>
<h3 id="文件重命名"><a href="#文件重命名" class="headerlink" title="文件重命名"></a>文件重命名</h3><p>文件快速重命名</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git mv 1.html 3.html</span><br><span class="line">git commit -m <span class="string">&#x27;mv 1.html to 3.html&#x27;</span></span><br></pre></td></tr></table></figure>

<p>注: 重命名之后, 查看 <code>3.html</code> 文件的修改历史不包括重命名之前的修改历史</p>
<h3 id="HEAD"><a href="#HEAD" class="headerlink" title="HEAD"></a>HEAD</h3><ul>
<li><code>HEAD</code> 表示当前最新的提交</li>
<li><code>HEAD~1</code> 表示上个版本</li>
<li><code>HEAD~2</code> 表示上上个版本</li>
</ul>
<h2 id="分支"><a href="#分支" class="headerlink" title="分支"></a>分支</h2><h3 id="创建分支"><a href="#创建分支" class="headerlink" title="创建分支"></a>创建分支</h3><p><code>git checkout -b new_branch [base_branch]</code></p>
<ul>
<li><code>new_branch</code> 新的分支名</li>
<li><code>base_branch</code> 基于指定的分支创建新的分支; 如果省略, 默认使用当前分支</li>
</ul>
<h3 id="分支切换"><a href="#分支切换" class="headerlink" title="分支切换"></a>分支切换</h3><p><code>git checkout branch_name</code></p>
<h3 id="删除分支"><a href="#删除分支" class="headerlink" title="删除分支"></a>删除分支</h3><p><code>git branch -d test_branch</code></p>
<p>注意: 不能删除当前分支</p>
<h2 id="修改-Message"><a href="#修改-Message" class="headerlink" title="修改 Message"></a>修改 Message</h2><p>修改前提: <strong>未提交到远程仓库</strong></p>
<p>用起来很神奇, 但是尽量少用</p>
<h3 id="修改最近的Message"><a href="#修改最近的Message" class="headerlink" title="修改最近的Message"></a>修改最近的Message</h3><p><code>git commit --amend</code></p>
<h3 id="修改旧的Message"><a href="#修改旧的Message" class="headerlink" title="修改旧的Message"></a>修改旧的Message</h3><p><code>git rebase -i pre_commit_id</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">5ba0afc (HEAD -&gt; master) git mv 1.html to 3.html</span><br><span class="line">9acb1bd second commit</span><br><span class="line">1a539e9 first commit</span><br></pre></td></tr></table></figure>

<p><code>r, reword &lt;commit&gt; = use commit, but edit the commit message</code></p>
<p>如果想要修改 <code>9acb1bd</code> 的提交历史, 需要使用 <code>9acb1bd</code> 上一个版本的 commit_id (1a539e9) , 例如: <code>git rebase -i 1a539e9</code></p>
<h3 id="合并连续-commit"><a href="#合并连续-commit" class="headerlink" title="合并连续 commit"></a>合并连续 commit</h3><p><code>git rebase -i pre_commit_id</code></p>
<p><code>s, squash &lt;commit&gt; = use commit, but meld into previous commit</code></p>
<h3 id="合并不连续-commit"><a href="#合并不连续-commit" class="headerlink" title="合并不连续 commit"></a>合并不连续 commit</h3><p><code>git rebase -i pre_commit_id</code></p>
<p>将多个不连续的 commit 放在一起</p>
<p><code>s, squash &lt;commit&gt; = use commit, but meld into previous commit</code></p>
<h2 id="文件对比"><a href="#文件对比" class="headerlink" title="文件对比"></a>文件对比</h2><h3 id="暂存区-和-HEAD-对比"><a href="#暂存区-和-HEAD-对比" class="headerlink" title="暂存区 和 HEAD 对比"></a>暂存区 和 HEAD 对比</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff --cached</span><br></pre></td></tr></table></figure>

<h3 id="工作区-和-暂存区对比"><a href="#工作区-和-暂存区对比" class="headerlink" title="工作区 和 暂存区对比"></a>工作区 和 暂存区对比</h3><p><code>git diff</code> 对比所有的文件<br><code>git diff file_name</code> 对比指定的文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git diff</span><br><span class="line">git diff ./2.html</span><br></pre></td></tr></table></figure>

<h2 id="版本回退"><a href="#版本回退" class="headerlink" title="版本回退"></a>版本回退</h2><h3 id="暂存区恢复"><a href="#暂存区恢复" class="headerlink" title="暂存区恢复"></a>暂存区恢复</h3><p>文件已经提交到暂存区, 准备 commit , 产品通知需求不改了; 最简单的方法就是清空缓存区</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset HEAD</span><br></pre></td></tr></table></figure>

<p>如果只回复暂存区部分文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset HEAD -- filename</span><br></pre></td></tr></table></figure>

<h3 id="工作区"><a href="#工作区" class="headerlink" title="工作区"></a>工作区</h3><p>基于一些需求, 工作区和暂存区文件不一致, 需要以暂存区为准, 同步工作区</p>
<p>同步单个文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- filename</span><br></pre></td></tr></table></figure>

<p>同步全部文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- .</span><br></pre></td></tr></table></figure>

<h3 id="删除最近几个commit"><a href="#删除最近几个commit" class="headerlink" title="删除最近几个commit"></a>删除最近几个commit</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard <span class="string">&quot;pre_commit_id&quot;</span></span><br></pre></td></tr></table></figure>

<h3 id="分支对比"><a href="#分支对比" class="headerlink" title="分支对比"></a>分支对比</h3><p>查看两个分支差异</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff branch_1 branch_2</span><br></pre></td></tr></table></figure>

<p>查看具体文件在两个分支间的差异</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff branch_1 branch_2 -- filename</span><br></pre></td></tr></table></figure>

<p>查看两个 commit 之间的差异</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff commit_id_1 commit_id_2</span><br></pre></td></tr></table></figure>

<h3 id="文件删除"><a href="#文件删除" class="headerlink" title="文件删除"></a>文件删除</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git rm 2.html</span><br><span class="line">git commit -m <span class="string">&quot;git delete 2.html&quot;</span></span><br></pre></td></tr></table></figure>

<h3 id="暂存"><a href="#暂存" class="headerlink" title="暂存"></a>暂存</h3><p>将暂存区和工作区暂时保存下来</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stage</span><br></pre></td></tr></table></figure>

<p>查看 stage 列表</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stage list</span><br></pre></td></tr></table></figure>

<p>取出 stage <code>git stage apply</code> 或者 <code>git stage pop</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stage apply</span><br></pre></td></tr></table></figure>

<p>区别: pop 取出之后就删除, apply 并不会删除记录</p>
<h3 id="忽略文件"><a href="#忽略文件" class="headerlink" title="忽略文件"></a>忽略文件</h3><p><code>.gitignore</code> 文件</p>
<p>注: <code>.gitignore</code> 文件可以有多个; 例如 laravel 项目: 项目根目录有 <code>.gitignore</code> 文件, <code> laravel/storage/app/</code> 目录下也有 <code>.gitignore</code> 文件 </p>
<p><code>doc/</code> 和 <code>doc</code> 区别:</p>
<ul>
<li><code>doc/</code> 忽略 <code>doc</code> 目录下的所有文件, 但不忽略 <code>doc</code> 目录</li>
<li><code>doc</code> 忽略 <code>doc</code> 目录下的所有文件以及 <code>doc</code> 目录</li>
</ul>
<p>支持正则表达式, 例如: <code>*.log</code></p>
<h2 id="远程"><a href="#远程" class="headerlink" title="远程"></a>远程</h2><p>添加远端仓库</p>
<p><code>git add remote &quot;remote_name&quot; &quot;remote_url&quot; </code></p>
<p>更新 </p>
<ul>
<li><code>git pull</code></li>
<li><code>git push</code></li>
</ul>
<p><code>git pull --rebase</code><br><code>git rebase --continue</code><br><code>git rebase --abort</code></p>

  </div>
  <!--文末结束语-->
  
    <div style="text-align:center;color: #ccc;font-size:24px;"> --- 本文结束 <i class="iconfont icon-heartbeat" style="font-size:24px;"></i> The End --- </div>
  
  <!--页脚广告-->
  
  <div class="mdui-divider"></div>
  
  <nav>
    
      <a rel="prev" class="post-nav-item mdui-float-left" href="/2020/10/22/JetBrain-%E6%BF%80%E6%B4%BB%E7%A0%81/">
        <i class="iconfont icon-angle-left"></i>
        <span>JetBrain 激活码</span>
      </a>
    
    
  </nav>
</article>




  <div class="toc-button"  style="z-index: 100;">
    <button class="mdui-fab mdui-ripple mdui-color-teal" mdui-menu="{target: '#toc'}"><i class="iconfont icon-list"></i></button>
    <ul class="mdui-menu" id="toc">
      <li class="mdui-menu-item">
        <a href="/2020/10/20/Git-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" id="toc-header" class="mdui-ripple">文章目录</a>
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE"><span class="toc-number">1.</span> <span class="toc-text">配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF%E9%85%8D%E7%BD%AE"><span class="toc-number">1.1.</span> <span class="toc-text">用户信息配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E9%85%8D%E7%BD%AE"><span class="toc-number">1.2.</span> <span class="toc-text">查看配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8"><span class="toc-number">2.</span> <span class="toc-text">基本使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Clone"><span class="toc-number">2.1.</span> <span class="toc-text">Clone</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Add"><span class="toc-number">2.2.</span> <span class="toc-text">Add</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%93%E5%BA%93"><span class="toc-number">2.3.</span> <span class="toc-text">初始化仓库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E4%BB%93%E5%BA%93%E7%8A%B6%E6%80%81"><span class="toc-number">2.4.</span> <span class="toc-text">查看仓库状态</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E5%88%B0%E7%BC%93%E5%AD%98%E5%8C%BA"><span class="toc-number">2.5.</span> <span class="toc-text">添加到缓存区</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%90%E4%BA%A4%E5%88%B0%E7%89%88%E6%9C%AC%E5%BA%93"><span class="toc-number">2.6.</span> <span class="toc-text">提交到版本库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E6%97%A5%E5%BF%97"><span class="toc-number">2.7.</span> <span class="toc-text">查看提交日志</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%87%E4%BB%B6%E9%87%8D%E5%91%BD%E5%90%8D"><span class="toc-number">2.8.</span> <span class="toc-text">文件重命名</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#HEAD"><span class="toc-number">2.9.</span> <span class="toc-text">HEAD</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E6%94%AF"><span class="toc-number">3.</span> <span class="toc-text">分支</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF"><span class="toc-number">3.1.</span> <span class="toc-text">创建分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E5%88%87%E6%8D%A2"><span class="toc-number">3.2.</span> <span class="toc-text">分支切换</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E5%88%86%E6%94%AF"><span class="toc-number">3.3.</span> <span class="toc-text">删除分支</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9-Message"><span class="toc-number">4.</span> <span class="toc-text">修改 Message</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%9C%80%E8%BF%91%E7%9A%84Message"><span class="toc-number">4.1.</span> <span class="toc-text">修改最近的Message</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%97%A7%E7%9A%84Message"><span class="toc-number">4.2.</span> <span class="toc-text">修改旧的Message</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%88%E5%B9%B6%E8%BF%9E%E7%BB%AD-commit"><span class="toc-number">4.3.</span> <span class="toc-text">合并连续 commit</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%88%E5%B9%B6%E4%B8%8D%E8%BF%9E%E7%BB%AD-commit"><span class="toc-number">4.4.</span> <span class="toc-text">合并不连续 commit</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%96%87%E4%BB%B6%E5%AF%B9%E6%AF%94"><span class="toc-number">5.</span> <span class="toc-text">文件对比</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9A%82%E5%AD%98%E5%8C%BA-%E5%92%8C-HEAD-%E5%AF%B9%E6%AF%94"><span class="toc-number">5.1.</span> <span class="toc-text">暂存区 和 HEAD 对比</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E5%8C%BA-%E5%92%8C-%E6%9A%82%E5%AD%98%E5%8C%BA%E5%AF%B9%E6%AF%94"><span class="toc-number">5.2.</span> <span class="toc-text">工作区 和 暂存区对比</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%89%88%E6%9C%AC%E5%9B%9E%E9%80%80"><span class="toc-number">6.</span> <span class="toc-text">版本回退</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9A%82%E5%AD%98%E5%8C%BA%E6%81%A2%E5%A4%8D"><span class="toc-number">6.1.</span> <span class="toc-text">暂存区恢复</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E5%8C%BA"><span class="toc-number">6.2.</span> <span class="toc-text">工作区</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%9C%80%E8%BF%91%E5%87%A0%E4%B8%AAcommit"><span class="toc-number">6.3.</span> <span class="toc-text">删除最近几个commit</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E5%AF%B9%E6%AF%94"><span class="toc-number">6.4.</span> <span class="toc-text">分支对比</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%87%E4%BB%B6%E5%88%A0%E9%99%A4"><span class="toc-number">6.5.</span> <span class="toc-text">文件删除</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9A%82%E5%AD%98"><span class="toc-number">6.6.</span> <span class="toc-text">暂存</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BF%BD%E7%95%A5%E6%96%87%E4%BB%B6"><span class="toc-number">6.7.</span> <span class="toc-text">忽略文件</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B"><span class="toc-number">7.</span> <span class="toc-text">远程</span></a></li></ol>
      </li>
    </ul>
  </div>



    <div id="comment" class="mdui-card mdui-p-a-2 mdui-m-b-5">
      <div class="mdui-tab" mdui-tab>
        
          <a href="#comment-tab0" class="mdui-ripple">gitalk</a>
        
          <a href="#comment-tab1" class="mdui-ripple">livere</a>
        
      </div>
      
        <div id="comment-tab0" class="mdui-p-a-2">
          <div id="gitalk-container"></div>
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/js-md5@0.7.3/src/md5.min.js"></script>
<script>
  var gitalk = new Gitalk({
    clientID: '',
    clientSecret: '',
    repo: '',
    owner: '',
    admin: [''],
    id:  md5(location.pathname) ,
    distractionFreeMode: 'true',
  });
  gitalk.render('gitalk-container');
</script>
        </div>
      
        <div id="comment-tab1" class="mdui-p-a-2">
          <div id="lv-container" data-id="city" data-uid="">
  <script type="text/javascript">
    (function (d, s) {
      var j, e = d.getElementsByTagName(s)[0];
      if (typeof LivereTower === 'function') { return; }
      j = d.createElement(s);
      j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
      j.async = true;
      e.parentNode.insertBefore(j, e);
    })(document, 'script');
  </script>
  <noscript>Please enable JavaScript to view the comments powered by LiveRe.</noscript>
</div>
        </div>
      
    </div>

  </main>
  <footer id="footer" class="mdui-text-center mdui-m-t-5 mdui-p-b-2 mdui-p-t-4 mdui-color-theme">
  <div class="mdui-container">
    <div class="mdui-row">
      
        <a href="https://beian.miit.gov.cn" rel="noopener" target="_blank"></a>
      
      <span>
        &copy; 2015 - 2021 
        
          <span style="color:#d9333f" class="iconfont icon-heart"></span>
        
        Demo deom
      </span>
    </div>
    <div class="mdui-row">
      
        <div class="mdui-col-xs-6 mdui-text-right">
          <span>Powered by <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a></span>
        </div>
        <div class="mdui-col-xs-6 mdui-text-left">
          <span>Theme: <a href="https://github.com/kb1000fx/Meadow" rel="noopener" target="_blank">Meadow</a></span>
        </div>
      
    </div>
    <div class="mdui-row">
      
        <div class="mdui-col-xs-6 mdui-text-right">
          <span id="busuanzi_container_site_uv" style="display: none;"> <span class="iconfont icon-user"></span>总访客量 <span id="busuanzi_value_site_uv"></span></span>
        </div>
        <div class="mdui-col-xs-6 mdui-text-left">
          <span id="busuanzi_container_site_pv" style="display: none;"> <span class="iconfont icon-eye"></span>总访问量 <span id="busuanzi_value_site_pv"></span></span>
        </div>
      
    </div>
 </div>
</footer>
  
  <button id="gotop" class="mdui-fab mdui-fab-fixed mdui-fab-hide mdui-ripple mdui-color-teal" style="z-index:100;"><i class="iconfont icon-arrowup"></i></button>
  
  

    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




    <script src="https://cdn.jsdelivr.net/npm/mermaid@8.4.8/dist/mermaid.min.js"></script>
    <script>mermaid.initialize({
        startOnLoad: true,
        theme: "default"
    });</script>




    
<script src="/js/mdui.min.v1.0.0.js"></script>




<script src="/js/meadow.js"></script>

</body>
</html >